package com.cloud.freeflow.api.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.cloud.freeflow.api.entity.ProcActEvent;
import com.cloud.freeflow.api.mapper.ProcActEventMapper;
import com.cloud.freeflow.api.service.ProcEventService;

import tk.mybatis.mapper.entity.Example;

@Service
public class ProcEventServiceImpl implements ProcEventService {

	@Autowired
	private ProcActEventMapper procActEventMapper;

	@Override
	public List<ProcActEvent> listEventsByActDefId(long actDefId) {
		Example example = new Example(ProcActEvent.class);
		Example.Criteria criteria = example.createCriteria();
		criteria.andEqualTo("actDefId", actDefId);
		return procActEventMapper.selectByExample(example);
	}

	@Override
	public void deleteEvent(long eventId) {
		procActEventMapper.deleteByPrimaryKey(eventId);
	}

	@Override
	public ProcActEvent saveUpdateEvent(ProcActEvent event) {
		Long eventId = event.getEventId();
		if (null == eventId || 0 == eventId) {
			event.setEventId(eventId);
			procActEventMapper.insert(event);
		} else {
			procActEventMapper.updateByPrimaryKey(event);
		}
		return event;
	}

}
